/**
 * 
 */
package com.cnc.tag;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;

import org.apache.struts.util.RequestUtils;

import com.cnc.bas.util.Constants;

/**
 * @author zzcclp
 *
 */
public class ListCode2Value extends LtcmTag {

	private String name;
	private String property;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	/**
	 * 
	 */
	public ListCode2Value() {
		// TODO Auto-generated constructor stub
		super();
	}

	public int doEndTag() throws JspException {
		try{
			
			HttpServletRequest request = (HttpServletRequest) pageContext
			.getRequest();
			
			//获取需要转换的值
			Object oValue = RequestUtils.lookup(pageContext, name, property, null);
			
			if (oValue == null || oValue.toString().equals("")){
				return super.doEndTag();
			}
			
			String dataStr = oValue.toString();
			
			StringBuffer sb = new StringBuffer();
			String[] temp = dataStr.split(",");
			int len = temp.length;
			for (int i = 0; i < len; i++){
				sb.append(((String)Constants.AE131SERVER.get(temp[i])) + ", ");
			}

			//去掉最后一个逗号
			String result = sb.toString().substring(0, sb.toString().length() - 2);
			pageContext.getOut().println(result);
			
			return super.doEndTag();

		} 
		catch (Exception e) {
			e.printStackTrace();
			throw new JspException(e.toString());
		}
	}

}
